﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
using DevExpress.XtraEditors;

namespace POS
{
    public partial class SplitTicket : DevExpress.XtraEditors.XtraUserControl
    {
        public class lineinfo
        {
            public static string qty;
            public static string Description;
            public static double Amount;
        }
        int ReceiptNo;
        double subtotal1 = 0;
        double tax1 = 0;
        double billtotal1 = 0;

        double subtotal2 = 0;
        double tax2 = 0;
        double billtotal2 = 0;

        double subtotal3 = 0;
        double tax3 = 0;
        double billtotal3 = 0;

        double subtotal4 = 0;
        double tax4 = 0;
        double billtotal4 = 0;

        public static string ServerNAME;
        public static string TableNAME;

        public SplitTicket(int receiptNo,string serverName,string TableName)
        {
            ReceiptNo = receiptNo;
            ServerNAME = serverName;
            TableNAME = TableName;
            InitializeComponent();

            lvTicketOne.BackColor = this.BackColor;
            lvTicketOne.ForeColor = this.ForeColor;
            lvTicketTwo.BackColor = this.BackColor;
            lvTicketTwo.ForeColor = this.ForeColor;
            lvTicketThree.BackColor = this.BackColor;
            lvTicketThree.ForeColor = this.ForeColor;
            lvTicketFour.BackColor = this.BackColor;
            lvTicketFour.ForeColor = this.ForeColor;
            lvOriginalTicket.BackColor = this.BackColor;
            lvOriginalTicket.ForeColor = this.ForeColor;


            lblBillTotal1.ForeColor = this.ForeColor;
            lblSubTotal1.ForeColor = this.ForeColor;
            lblTaxTotal1.ForeColor = this.ForeColor;
            lblBillTotal2.ForeColor = this.ForeColor;
            labelControl2.ForeColor = this.ForeColor;
            labelControl3.ForeColor = this.ForeColor;
            labelControl4.ForeColor = this.ForeColor;
            lblTaxTotal2.ForeColor = this.ForeColor;
            labelControl6.ForeColor = this.ForeColor;
            labelControl7.ForeColor = this.ForeColor;
            lblSubTotal2.ForeColor = this.ForeColor;
            labelControl9.ForeColor = this.ForeColor;
            lblBillTotal4.ForeColor = this.ForeColor;
            labelControl11.ForeColor = this.ForeColor;
            labelControl12.ForeColor = this.ForeColor;
            labelControl13.ForeColor = this.ForeColor;
            lblTaxTotal4.ForeColor = this.ForeColor;
            labelControl15.ForeColor = this.ForeColor;
            labelControl16.ForeColor = this.ForeColor;
            lblSubTotal4.ForeColor = this.ForeColor;
            labelControl18.ForeColor = this.ForeColor;
            lblBillTotal3.ForeColor = this.ForeColor;
            labelControl20.ForeColor = this.ForeColor;
            labelControl21.ForeColor = this.ForeColor;
            lblTaxTotal3.ForeColor = this.ForeColor;
            labelControl23.ForeColor = this.ForeColor;
            lblSubTotal3.ForeColor = this.ForeColor;
            labelControl25.ForeColor = this.ForeColor;


        }

        private void SplitTicket_Load(object sender, EventArgs e)
        {
            foreach (DataRow row in DataTableClass.ReceiptData.Rows)
            {
                if (row["ReceiptNo"].ToString().Trim().Contains(ReceiptNo.ToString()))
                {
                    ListViewItem lvi = new ListViewItem(row["ReceiptQty"].ToString().Trim());
                    lvi.SubItems.Add(row["ReceiptDescription"].ToString().Trim());
                    lvi.SubItems.Add(row["ReceiptItemTotal"].ToString().Trim());
                    
                    lvOriginalTicket.Items.Add(lvi);
                }
            }


        }

        private void lvTicketOne_MouseDown(object sender, MouseEventArgs e)
        {

            lineinfo.qty = lvOriginalTicket.SelectedItems[0].SubItems[0].Text;
            lineinfo.Description = lvOriginalTicket.SelectedItems[0].SubItems[1].Text;
            lineinfo.Amount = Convert.ToDouble(lvOriginalTicket.SelectedItems[0].SubItems[2].Text);

            ListViewItem lvi = new ListViewItem(lineinfo.qty);
            lvi.SubItems.Add(lineinfo.Description);
            lvi.SubItems.Add(lineinfo.Amount.ToString("C"));

            lvTicketOne.Items.Add(lvi);

            lvOriginalTicket.SelectedItems[0].Remove();

            subtotal1 = subtotal1 + lineinfo.Amount;
            lblSubTotal1.Text = subtotal1.ToString("C");

            tax1 = subtotal1 * 0.0825;
            lblTaxTotal1.Text = tax1.ToString("C");

            billtotal1 = subtotal1 + tax1;
            lblBillTotal1.Text = billtotal1.ToString("C");
        }

        private void lvTicketTwo_MouseDown(object sender, MouseEventArgs e)
        {
            lineinfo.qty = lvOriginalTicket.SelectedItems[0].SubItems[0].Text;
            lineinfo.Description = lvOriginalTicket.SelectedItems[0].SubItems[1].Text;
            lineinfo.Amount = Convert.ToDouble(lvOriginalTicket.SelectedItems[0].SubItems[2].Text);

            ListViewItem lvi = new ListViewItem(lineinfo.qty);
            lvi.SubItems.Add(lineinfo.Description);
            lvi.SubItems.Add(lineinfo.Amount.ToString("C"));

            lvTicketTwo.Items.Add(lvi);

            lvOriginalTicket.SelectedItems[0].Remove();

            subtotal2 = subtotal2 + lineinfo.Amount;
            lblSubTotal2.Text = subtotal2.ToString("C");

            tax2 = subtotal2 * 0.0825;
            lblTaxTotal2.Text = tax2.ToString("C");

            billtotal2 = subtotal2 + tax2;
            lblBillTotal2.Text = billtotal2.ToString("C");
        }

        private void lvTicketThree_MouseDown(object sender, MouseEventArgs e)
        {
            lineinfo.qty = lvOriginalTicket.SelectedItems[0].SubItems[0].Text;
            lineinfo.Description = lvOriginalTicket.SelectedItems[0].SubItems[1].Text;
            lineinfo.Amount = Convert.ToDouble(lvOriginalTicket.SelectedItems[0].SubItems[2].Text);

            ListViewItem lvi = new ListViewItem(lineinfo.qty);
            lvi.SubItems.Add(lineinfo.Description);
            lvi.SubItems.Add(lineinfo.Amount.ToString("C"));

            lvTicketThree.Items.Add(lvi);

            lvOriginalTicket.SelectedItems[0].Remove();

            subtotal3 = subtotal3 + lineinfo.Amount;
            lblSubTotal3.Text = subtotal3.ToString("C");

            tax3 = subtotal3 * 0.0825;
            lblTaxTotal3.Text = tax3.ToString("C");

            billtotal3 = subtotal3 + tax3;
            lblBillTotal3.Text = billtotal3.ToString("C");
        }

        private void lvTicketFour_MouseDown(object sender, MouseEventArgs e)
        {
            lineinfo.qty = lvOriginalTicket.SelectedItems[0].SubItems[0].Text;
            lineinfo.Description = lvOriginalTicket.SelectedItems[0].SubItems[1].Text;
            lineinfo.Amount = Convert.ToDouble(lvOriginalTicket.SelectedItems[0].SubItems[2].Text);

            ListViewItem lvi = new ListViewItem(lineinfo.qty);
            lvi.SubItems.Add(lineinfo.Description);
            lvi.SubItems.Add(lineinfo.Amount.ToString("C"));

            lvTicketFour.Items.Add(lvi);

            lvOriginalTicket.SelectedItems[0].Remove();

            subtotal4 = subtotal4 + lineinfo.Amount;
            lblSubTotal4.Text = subtotal4.ToString("C");

            tax4 = subtotal4 * 0.0825;
            lblTaxTotal4.Text = tax4.ToString("C");

            billtotal4 = subtotal4 + tax4;
            lblBillTotal4.Text = billtotal4.ToString("C");
        }
    }
}
